﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class userbackstage_update1 : System.Web.UI.Page
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString.ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        string release = Session["name"].ToString();
        string sqlstr = "select * from info where release='" + release + "'";
        SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        if (!IsPostBack)
        {
            BindData();
        }
    }
    public void BindData()
    {
        string release = Session["name"].ToString();
        string sqlstr = "select * from info where release='"+release+"'";

        SqlDataAdapter da = new SqlDataAdapter(sqlstr, conn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindData();
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
        string Type1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
        string title1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[2].Controls[0])).Text.ToString().Trim();
        string information1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[3].Controls[0])).Text.ToString().Trim();
        string linkman1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim();
        string tel1 = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Text.ToString().Trim();
        string update_sql = "update info set type='" + Type1 + "',title='" + title1 + "',info='" + information1 + "',linkman='" + linkman1 + "',tel='" + tel1 + "' where ID='" + id + "'";
        bool update = ExceSQL(update_sql);
        if (update)
        {
            Response.Write("<script>alert('修改成功！')</script>");
            GridView1.EditIndex = -1;
            BindData();
        }
        else
        {

            Response.Write("<script>alert('修改失败！');</script>");

        }
    }

    public bool ExceSQL(string strSqlCom)
    {


        SqlCommand sqlcom = new SqlCommand(strSqlCom, conn);
        try
        {
            if (conn.State == System.Data.ConnectionState.Closed)
            { conn.Open(); }
            sqlcom.ExecuteNonQuery();
            return true;
        }
        catch
        {
            return false;
        }
        finally
        {
            conn.Close();
        }
    }

    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindData();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{

        //    if (e.Row.Cells[6].Text == "False")
        //    {
        //        e.Row.Cells[6].Text = "<span style='color:red'>" + "未审核" + "</span>";
        //    }
        //    else
        //    {
        //        e.Row.Cells[6].Text = "<span style='color:blue'>" + "已审核" + "</span>";
        //    }
        //}
    }
}